package com.sicheng.蓝桥.省赛.十三届;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/5/2 11:16
 */
public class 切分子数组dfs {
    static long count;
    public static void main(String[] args) {
        int[] nums = {6, 1, 3, 2, 4, 5, 7, 9, 8};
        boolean[][] dp = new boolean[nums.length][nums.length];
        initDp(dp, nums);
        dfs(nums, 0, dp);
        System.out.println(count);
    }

    // 区间[i,j]的数是连续的
    private static void initDp(boolean[][] dp, int[] nums) {
        for (int i = 0; i < dp.length; i++) {
            int max = nums[i];
            int min = nums[i];
            for (int j = i; j < dp.length; j++) {
                max = Math.max(max, nums[j]);
                min = Math.min(min, nums[j]);
                if (max - min == j - i)
                    dp[i][j] = true;
            }
        }
    }

    private static void dfs(int[] nums, int start, boolean[][] dp) {
        if (start == nums.length) {
            count++;
            return;
        }

        for (int i = start; i < nums.length; i++) {
            if (!dp[start][i]) {
                continue;
            }
            dfs(nums, i + 1, dp);
        }
    }
}
